
*******************************************************************************************
*******************************************************************************************
******************** Reclassification Risk in the Small Group Health Insurance Market
******************* by Sebastian Fleitas, Gautam Gowrisankaran and Anthony Lo Sasso 
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
******************** Table 5 Panel A and C 
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************

cd "~/Dropbox/ReclassificationRisk/"
use database_individual_level.dta, replace 

 do Restat_Final_Table3_USIC.do
 do Restat_Final_Table4_EnrolleeLevel.do

preserve
****************************************************************************************************************************
**** USE SPLINES TO TEST HHW PREDICTIONS
****************************************************************************************************************************
*** Second Implication fixed effects
*use aux_todrop_forSE.dta, clear
set more off 
gen dif_year = max_year - min_year
tab dif_year
gen laggedrisk = D.mean_pred_riskscore_rp
drop if dif_year<2 /*leaving only people with three complete observations*/
drop splinerisk1 splinerisk2
mkspline splinerisk1 0 splinerisk2 = laggedrisk if year==2015 /*making the spline on the delta for 2015, cross section estimate */
gen deltapremium = D.mean_premium
gen deltarisk  = D.mean_pred_riskscore_rp
gen deltaprob  = D.prob_leaving
gen deltaprob2 = D.prob_leaving2
gen deltaprob3 = D.prob_leaving3
gen deltaprob4 = D.prob_leaving4
gen deltaprob5 = D.prob_leaving5
gen deltaprob6 = D.prob_leaving6
drop if year<2015
reghdfe deltapremium splinerisk1 splinerisk2  yeardum* if sample==1 ,  noabsorb vce(cluster customer_number )
reghdfe deltapremium splinerisk1 splinerisk2 deltaprob  if sample==1 ,  noabsorb vce(cluster customer_number)
reghdfe deltapremium splinerisk1 splinerisk2 deltaprob deltaprob2 deltaprob3 deltaprob4 deltaprob5 deltaprob6  if sample==1 ,  noabsorb 
gen ind_insample = e(sample) 
drop if ind_insample!=1 
sort mbr_sys_id
keep mbr_sys_id
save ind_insample.dta, replace


restore
****************************************************************************************************************************
****************************************************************************************************************************
****************************************************************************************************************************
preserve
****************************************************************************************************************************
*** Second Implication no fixed effects 
set more off
*use aux_todrop_forSE.dta, clear
sort mbr_sys_id
merge mbr_sys_id using ind_insample.dta
drop if _merge!=3
drop if year<2014
drop splineriskA splineriskB
mkspline splineriskA 1 splineriskB = mean_pred_riskscore_rp 
reghdfe mean_premium splineriskA splineriskB   marketdum* yeardum* if sample==1 ,  noabsorb vce(cluster customer_number year)
reghdfe mean_premium splineriskA splineriskB prob_leaving  marketdum* yeardum* if sample==1 ,  noabsorb vce(cluster customer_number year)
reghdfe mean_premium splineriskA splineriskB prob_leaving* marketdum* yeardum* if sample==1 ,  noabsorb vce(cluster customer_number year)
****************************************************************************************************************************
restore 
